﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace CoreMobile.cmd
{
    public abstract class Command
    {

        protected IParameter parameter;
        protected string token="nil";
       // public static string CMD;

       protected Command()
       {

           init();

           //CMD = this.token;
       }

        protected abstract void init();

      

        public IParameter Parameter
        {
            get { return this.parameter; }
            set { this.parameter = value; }
        }

        
        public string Token
        {
            get { return token; }
        }

        public Command setParameter(IParameter ip)
        {
            this.parameter = ip;
            return this;
        }



       
        

    }

    public abstract class SendCommand : Command
    {
        public string asLine()
        {
            return this.token
                   + VABProtocol.ELEMENT_SEPARATOR
                   + this.parameterAsLine();
        }

        public string parameterAsLine()
        {
            string line = "";
            foreach (var param in this.parameters())
            {
                line += (""+VABProtocol.ELEMENT_SEPARATOR) + param;
            }

            return line.Substring(1); //1 = |ELMENT_SEPARATOR|
        }

        public abstract string[] parameters();
    }

    public abstract class ReceiveCommand : Command
    {
        public ReceiveCommand(string[] parameters): base()
        {
            this.parameter = this.fromParameterLine(parameters);
        }
        public ReceiveCommand() : base()
        {
        }

        public abstract IParameter fromParameterLine(string[] parameters);
    }
}
